package edu.sjtu.context.core;

/**
 * Maintain the context topic.
 * The user can use the default TopicManager or implement there own TopicManager
 * @author Roger
 *
 */
public interface TopicManager {
	/**
	 * Use to create a set of topics. This method will be used by the user to create topics.
	 * @param topics
	 * 		name of topics to be created.
	 * @exception Exception
	 * 		if any problem occurred during the creation process, throw an exception.
	 */
	public void createTopics(String[] topics)
	throws Exception;
	
	/**
	 * Publish message to a certain topic, which is indicated by the parameter topicName. 
	 * If the topic is not exist, this method will create one, and then publish the message
	 * to the topic.
	 * @param topicName
	 * 		the name of the topic
	 * @param msg
	 * 		the message to be published
	 * @exception Exception
	 * 		if any problem occurred during the publish process, throw an exception.
	 */
	public void publish(String topicName, ContextMessage msg)
	throws Exception;
	
	/**
	 * Use this method to get connection to a certain message broker.
	 * @param connectionUrl
	 * 		connection url to connect to message broker.
	 * @exception Exception
	 * 		if any problem occurred during create connection, throw an Exception
	 */
	public void getConnection(String connectionUrl)
	throws Exception;
	
	/**
	 * shot down the message broker.
	 */
	public void shutDown();
	
	/**
	 * To check whether a certain topic is already exist.
	 * @param topicName
	 * 		the name of the topic.
	 * @return
	 * 		if the topic is already exist then return true, or return false;
	 */
	public boolean isExsit(String topicName);
}
